
interface Animal {

  name: string;



  say:()=>void;


}
class Animal {

  // private name:string;    //ts中的private  只能在类的内部使用
  // protected name: string;    //protected  只能在类的内部和其继承的类使用

  name:string;
  //静态属性
  static age: number = 2;  //和java 一样都只能被类本身调用;不能被实例调用
  constructor(name:string) {
    this.name = name;
  }

  static isAnimal(instace): boolean {
    return instace instanceof Animal
  }
  run() {
    return 'running'
  }
}

const snake = new Animal('lucy');
const isnimale:boolean = Animal.isAnimal(snake);
console.log(isnimale);
snake.name = 'lili'
class Dog extends Animal {
  bark() {
    return `${this.name} is barking`
  }
}

class Cat extends Animal {
  constructor(name:string) {
    super(name);
  }
  miao = function () {
    console.log(`${this.name}喵`);
  }
  //重写run 方法
  run() {
    console.log('喵' + `${this.name}` + super.run());
    return '喵' + `${this.name}` + super.run();
  }
}

const dog = new Dog('狗');
const cat = new Cat('小花');
console.log(dog.bark());
console.log(dog.run());
cat.miao();
cat.run();

interface Radio {
  switchRadio():void;
}

interface Battery {
  checkBatterStatus():void;
}

class Car implements Radio {
  switchRadio() {
    console.log('kai')
  }
}

class CellPhone implements Radio,Battery {
  switchRadio() {
    console.log('关闭')
  }
  checkBatterStatus(){
    console.log('good');
  }
}